package com.lhf.azkaban.springbatch.example.batchprocessing;

import com.lhf.azkaban.springbatch.example.mode.RepayOrderInfo;
import com.lhf.azkaban.springbatch.example.utils.DateUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Author:95780
 * @Date: 17:53 2019/11/20
 * @Description: RepayOrder处理
 */
//@StepScope
public class RepayOrderProcessor implements ItemProcessor<RepayOrderInfo, RepayOrderInfo> {
    private static final Logger logger = LogManager.getLogger(RepayOrderProcessor.class);
//    @Value("#{jobParameters[jobname]}")
//    private String jobname;
//    @Value("#{jobParameters[jobpath]}")
//    private String jobpath;
    @Override
    public RepayOrderInfo process(RepayOrderInfo order) throws Exception {
        logger.info("======RepayOrderProcessor Begin ======   time:   " + DateUtil.parseDateTime(LocalDateTime.now(), DateUtil.PATTERN_DEFAULT_DATA));
//        logger.info("=======================================================");
//        logger.info("=======================================================");
//        logger.info("=======================================================");
//        logger.info("RepayOrderProcessor   ======= jobname " + jobname);
//        logger.info("RepayOrderProcessor   ======= jobpath " + jobpath);
//        logger.info("+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+");
//        logger.info("+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+");
        //数据进行封装
        RepayOrderInfo repayOrderInfo = new RepayOrderInfo();
        BeanUtils.copyProperties(order,repayOrderInfo);
        repayOrderInfo.setBussDate(new Date());

        //跳过数据
        /*if("049826".equals(repayOrderInfo.getUserId())){
            //throw new MySkipException("skip data");
            logger.info("中断退出，测试ActionLog是否会回滚");
            throw new RuntimeException("中断退出，测试ActionLog是否会回滚");
        }*/

        return repayOrderInfo;
    }
}
